<template>
  <div :style="'height:' + height">
    <iframe :src="url" style="width: 100%; height: 100%"/>
  </div>
</template>
<script>
import {getToken} from "@/utils/auth";

export default {
  name: "WarmFlow",
  data() {
    return {
      height: document.documentElement.clientHeight - 94.5 + "px;",
      url: ""
    };
  },
  mounted() {
    this.url = process.env.VUE_APP_BASE_API + `/warm-flow-ui/index.html?id=${this.$route.params.id}&disabled=${this.$route.query.disabled}&Authorization=Bearer ` + getToken();
    // this.url = `http://localhost:81/warm-flow-ui/index.html?id=${this.$route.params.id}&disabled=${this.$route.query.disabled}&Authorization=Bearer ` + getToken();
    // this.url = `http://localhost:82/warm-flow-ui/index.html?id=${this.$route.params.id}&disabled=${this.$route.query.disabled}&Authorization=Bearer ` + getToken();

    this.iframeLoaded();
  },
  methods: {
    iframeLoaded() {
      window.onmessage = (event) => {
        console.log(event);
        switch (event.data.method) {
          case "close":
            this.close();
            break;
        }
      }
    },
    close() {
      const obj = { path: "/flow/definition" };
      this.$tab.closeOpenPage(obj);
    }
  }
};
</script>
